var { randomUtils, textUtils, logUtils } = require("../../utils/index");
var adCommon = require("../adCommon");
var adType1 = require("./adType1");
var adType2 = require("./adType2");
var adType3 = require("./adType3");
var adType4 = require("./adType4");
var MAX_AD_INTERVAL = 45;
module.exports = {
  startWatchAd(maxAdCount) {
    adCommon.adCount = 0;
    adCommon.maxAdCount = maxAdCount || 5;
    this.getAdType();
  },
  getAdType() {
    var span = randomUtils.getRandom(MAX_AD_INTERVAL, MAX_AD_INTERVAL + 5);
    for (var index = 0; index < 5; index++) {
      var content = "直播间观看时长";
      if (textUtils.existsTextStartsWith(content)) {
        logUtils.info("adType:4");
        adType4.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      var content = "秒后得";
      if (textUtils.existsTextEndsWith(content)) {
        logUtils.info("adType:3");
        adType3.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      var content = "跳过";
      if (textUtils.existsTextEndsWith(content)) {
        logUtils.info("adType:2");
        adType2.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      var content = "后可领奖励";
      if (textUtils.existsTextEndsWith(content)) {
        logUtils.info("adType:1");
        adType1.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      sleep(2 * 1000);
    }
    logUtils.info("番茄", "未知的adType");
  },
};
